<template>
  <div class="app-container">
    <label class="title"
           style="font-size: 20px;color: rgba(0,0,0,.85);font-weight: 600;line-height: 32px">考生变更日志</label>

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="关键字" prop="main">
        <el-input
          v-model="queryParams.main"
          placeholder="输入准考号、考生姓名查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="candidateChange">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{scope.$index+(queryParams.pageNo-1)*queryParams.pageSize+1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="准考号" align="center" prop="zkz" width="100"/>
      <el-table-column label="考生姓名" align="center" prop="ksName" width="100"/>
      <el-table-column label="考点名称" align="center" prop="pointName" width="150"/>
      <el-table-column label="更改人" align="center" prop="changedBy" width="100"/>
      <el-table-column label="更改之前" align="center" prop="beforeChange">
        <template scope="scope">
          <span style="color: red">{{beforeData(scope.row.beforeChange)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="更改之后" align="center" prop="afterChange" style="text-align: left">
        <template scope="scope">
          <span style="color: blue;">{{afterData(scope.row.afterChange)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="更改时间" align="center" prop="gmtModified" width="150"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>
<style>
  .el-table .cell {
    white-space: pre-line; /*保留换行符*/
  }
</style>
<script>
  import {
    list,
    del
  } from '@/api/business/candidateChange/candidateChange'

  export default {
    name: 'candidateChange',
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 考生变更日志表格数据
        candidateChange: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          main: null
        }
      }
    },
    created() {
      this.getList()
    },
    methods: {
      getList() {
        this.loading = true
        list(this.queryParams).then(response => {
          this.candidateChange = response.data.records
          this.total = response.data.totalCount
          this.loading = false
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      beforeData(beforeChange) {
        beforeChange = beforeChange.substring(1, beforeChange.length - 1)
        beforeChange = beforeChange.replaceAll(',', ' \n ')
        beforeChange = beforeChange.replaceAll('"', '')
        beforeChange = beforeChange.replaceAll(':', ': ')
        return beforeChange
      },
      afterData(afterChange) {
        afterChange = afterChange.substring(1, afterChange.length - 1)
        afterChange = afterChange.replaceAll(',', ' \n ')
        afterChange = afterChange.replaceAll('"', '')
        afterChange = afterChange.replaceAll(':', ': ')
        return afterChange
      }
    }
  }
</script>
